﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

using FRL.DebtChased.Silverlight.Library.RichContentService;

namespace FRL.DebtChased.AgentEditor
{

	/// <summary>
	/// Declaration of SearchResultsWnd class
	/// A list of agents that the user can selected one from
	/// </summary>
	public partial class SearchResultsWnd : ChildWindow
	{

		/////////////////////////////////////////////////////////////
		// Attributes

		private int m_iSelectedAgentId = 0;
		public int SelectedAgentId
		{
			get { return m_iSelectedAgentId; }
		}

		/////////////////////////////////////////////////////////////
		// Construction

		public SearchResultsWnd( List<AgentSummaryTransport> results )
		{

			// Load xaml resources
			InitializeComponent();

			// Load the list
			lstAgent.ItemsSource = results;

			// Setup controls
			_setupControls();

		}

		/////////////////////////////////////////////////////////////
		// Event Handlers

		private void OKButton_Click(object sender, RoutedEventArgs e)
		{

			// Get the selected agent
			AgentSummaryTransport selected = lstAgent.SelectedValue as AgentSummaryTransport;
			m_iSelectedAgentId = selected.AgentId;

			// Close dialog
			this.DialogResult = true;

		}

		private void CancelButton_Click(object sender, RoutedEventArgs e)
		{

			// Close dialog
			this.DialogResult = false;

		}

		private void lstAgent_SelectionChanged(object sender, SelectionChangedEventArgs e)
		{

			// Setup controls
			_setupControls();

		}

		/////////////////////////////////////////////////////////////
		// Operations

		private void _setupControls()
		{

			// Enable/disable controls
			OKButton.IsEnabled = (lstAgent.SelectedIndex != -1);

		}

	}

}

